package com.zyj.eps.controller;

import com.alibaba.fastjson.JSON;
import com.zyj.eps.pojo.News;
import com.zyj.eps.pojo.Utils;
import com.zyj.eps.service.NewsServiceImpl;
import com.zyj.eps.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;

/**
 * @author super
 * @date 2022/3/27 14:46
 */
@Controller
@RestController
@CrossOrigin
@SuppressWarnings("all")//抑制警告
public class NewsController {
    @Autowired
    private UserServiceImpl userService;
    @Autowired
    private NewsServiceImpl newsService;

    @RequestMapping("/newstupian")
    public String getAllUser(@RequestBody Utils utils){
        System.out.println("访问成功"+ utils.getImgsStr());
        HashMap<String, Object> map = new HashMap<>();
        map.put("hh", utils.getImgsStr());
        return JSON.toJSONString(map);
    }

    @RequestMapping("/getAllNews")
    public String getAllNews(){
        List<News> allNews = newsService.getAllNews();
        Collections.reverse(allNews); //实现list集合逆序排列
        return JSON.toJSONString(allNews);
    }
    @RequestMapping("/getNewsByTitle")
    public String getNewsByTitle(String title){
        News newsByTitle = newsService.getNewsByTitle(title);
        return JSON.toJSONString(newsByTitle);
    }
}
